package com.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class ObjectOutputStream_ {
    public static void main(String[] args) {
        String filePath = "d:\\date.dat";
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filePath));
            oos.writeInt(100);//将int转为包装类
            oos.writeBoolean(true);
            oos.writeChar('a');
            oos.writeUTF("zkl");
            oos.writeObject(new Dog("a"));
            oos.close();
            System.out.println("ok");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
class Dog implements Serializable {//要序列化就必须要实现Serializable接口
    private String name;
    public Dog(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                '}';
    }
}